//
// Created by PC on 2024/4/18.
//


#include <iostream>
#include <vector>
#include "linkedListUtil.h"
using namespace std;


Node * reverse(Node * h)
{
    h=h->next; // 对于有头结点的链表需要有这一句
    Node *pre = nullptr;
    Node *cur = nullptr;
    while (h)
    {
        cur=h->next;
        h->next=pre;
        pre=h;
        h=cur;
    }
    h = new Node {-1,pre};
    return h;
}

int main()
{
    vector<int> l={0,1,2,3,4,5};
    Node *head = build(l);
    printLinkedList(head);
    Node *h= reverse(head);
    printLinkedList(h);

    return 0;
}